package com.xulu.romance.filter;

import java.util.HashSet;
import java.util.Set;

public class SensitiveWordFilter {
    private static Set<String> sensitiveWords;

    public SensitiveWordFilter() {
        sensitiveWords = new HashSet<>();

        // 将敏感词添加到HashSet中
        sensitiveWords.add("黄色");
        sensitiveWords.add("傻逼");
        sensitiveWords.add("流氓");

    }

    public static String filter(String text) {
        String replacement = "***";
        if (sensitiveWords == null) {
            // 处理敏感词集合为null的情况，例如给出一个默认的替换符号
            return text.replaceAll("\\b(黄色|傻逼|流氓)\\b", "***");
        }
        for (String word : sensitiveWords) {
            if (text.contains(word)) {
                text = text.replaceAll(word, replacement);
            }
        }
        return text;
    }



}
